<!DOCTYPE html >
<html>
<head>
    <link rel="stylesheet" href="demos.css" type="text/css" media="screen" />
    
    <script src="../libraries/RGraph.common.core.js" ></script>
    <script src="../libraries/RGraph.common.key.js" ></script>
    <script src="../libraries/RGraph.bar.js" ></script>
    
    <title>RGraph demo: A stacked bar chart</title>

    <meta name="robots" content="noindex,nofollow" />
    <meta name="description" content="A demonstration of a stacked Bar chart. The chart uses the ondraw event to add some text to the chart" />
     
</head>
<body>

    <!-- Share buttons -->
    <p style="float: right">
        <script>
            document.write('<a href="" target="_blank" onclick="window.open(\'https://www.facebook.com/sharer/sharer.php?u=http://www.rgraph.net' + location.pathname + '\', null, \'top=50,left=50,width=600,height=368\'); return false"><img src="../images/facebook-large.png" width="200" height="43" alt="Share on Facebook" border="0" title="Visit the RGraph Facebook page" id="facebook_link" /></a>&nbsp;');
            document.write('<a href="https://twitter.com/_rgraph" target="_blank" onclick="window.open(\'https://twitter.com/intent/tweet?text=Check%20out%20this%20demo%20of%20RGraph:%202D/3D%20JavaScript%20charts%20-%20Free%20and%20Open%20Source%20http://www.rgraph.net' + location.pathname + '\', null, \'top=50,left=50,width=700,height=400\'); return false"><img src="../images/twitter-large.png" width="200" height="43" alt="Share on Twitter" border="0" title="Mention RGraph on Twitter" id="twitter_link" /></a>');
        </script>
    </p>

        
    <h1>A stacked bar chart</h1>
    
    <p>
        This is a stacked Bar chart. The labels that are inside the bars are achieved by using a DOM1 style ondraw event.
    </p>

    <canvas id="cvs" width="700" height="350">[No canvas support]</canvas>

    <script>
        window.onload = function ()
        {
            var canvas = document.getElementById("cvs");

            var bar = new RGraph.Bar({
                id: 'cvs',
                data: [[5.33,2.33,3.32],[3.42,2.23,4.23],[4.23,3.23,4.99], [7.99,2.98,2.35], [2.75,1.02,5.24]],
                options: {
                    grouping: 'stacked',
                    labels: ['John','James','Fred','Luke','Luis'],
                    labelsAbove: true,
                    labelsAboveDecimals: 2,
                    linewidth: 2,
                    strokestyle: 'white',
                    colors: ['Gradient(#4572A7:#66f)','Gradient(#AA4643:white)','Gradient(#89A54E:white)'],
                    shadow: true,
                    shadowOffsetx: 1,
                    shadowOffsety: 1,
                    shadowBlur: 10,
                    hmargin: 25,
                    gutterLeft: 45,
                    backgroundGridVlines: false,
                    backgroundGridBorder: false,
                    key: ['Monday','Tuesday','Wednesday'],
                    keyColors: ['blue','#c00','#0c0'],
                    keyPosition: 'gutter',
                    keyPositionX: canvas.width - 300,
                    keyPositionY: 18,
                    keyPositionGutterBoxed: true,
                    axisColor: '#ccc',
                    noyaxis: true,
                    textAccessible: true
                }
            }).on('draw', function (obj)
            {
                for (var i=0; i<obj.coords.length; ++i) {
                    obj.context.fillStyle = 'white';
                    RGraph.Text2(obj.context, {
                        font:'Verdana',
                        'size':10,
                        'x':obj.coords[i][0] + (obj.coords[i][2] / 2),
                        'y':obj.coords[i][1] + (obj.coords[i][3] / 2),
                        'text':obj.data_arr[i].toString(),
                        'valign':'center',
                        'halign':'center'
                    });
                }
            }).draw();
        };
    </script>








    <p></p>

    This goes in the documents header:
    <pre class="code">
&lt;script src="RGraph.common.core.js"&gt;&lt;/script&gt;
&lt;script src="RGraph.common.key.js"&gt;&lt;/script&gt;
&lt;script src="RGraph.bar.js"&gt;&lt;/script&gt;
</pre>
    
    Put this where you want the chart to show up:
    <pre class="code">
&lt;canvas id="cvs" width="600" height="250"&gt;
    [No canvas support]
&lt;/canvas&gt;
</pre>

    This is the code that generates the chart:
    <pre class="code">
&lt;script&gt;
    window.onload = function ()
    {
        var canvas = document.getElementById("cvs");

        var bar = new RGraph.Bar({
            id: 'cvs',
            data: [[5.33,2.33,3.32],[3.42,2.23,4.23],[4.23,3.23,4.99], [7.99,2.98,2.35], [2.75,1.02,5.24]],
            options: {
                grouping: 'stacked',
                labels: ['John','James','Fred','Luke','Luis'],
                labelsAbove: true,
                labelsAbovedecimals: 2,
                linewidth: 2,
                strokestyle: 'white',
                colors: ['Gradient(#4572A7:#66f)','Gradient(#AA4643:white)','Gradient(#89A54E:white)'],
                shadow: true,
                shadowOffsetx: 1,
                shadowOffsety: 1,
                shadowBlur: 10,
                hmargin: 25,
                gutterLeft: 45,
                backgroundGridVlines: false,
                backgroundGridBorder: false,
                key: ['Monday','Tuesday','Wednesday'],
                keyColors: ['blue','#c00','#0c0'],
                keyPosition: 'gutter',
                keyPositionX: canvas.width - 300,
                keyPositionY: 18,
                keyPositionGutterBoxed: true,
                axisColor: '#ccc',
                noyaxis: true,
                textAccessible: true
            }
        }).on('draw', function (obj)
        {
            for (var i=0; i&lt;obj.coords.length; ++i) {
                obj.context.fillStyle = 'white';
                RGraph.Text2(obj.context, {
                    font:'Verdana',
                    'size':10,
                    'x':obj.coords[i][0] + (obj.coords[i][2] / 2),
                    'y':obj.coords[i][1] + (obj.coords[i][3] / 2),
                    'text':obj.data_arr[i].toString(),
                    'valign':'center',
                    'halign':'center'
                });
            }
        }).draw();
    };
&lt;/script&gt;
</pre>



    
    <p>
        <a href="./">&laquo; Back</a>
    </p>

</body>
</html>